import com.alibaba.fastjson.JSON;
import com.cangshi.entity.User;
import com.cangshi.service.UserService;
import org.apache.log4j.Logger;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by Eoly on 2016/11/15.
 */

@RunWith(SpringJUnit4ClassRunner.class)

@ContextConfiguration(locations = {"classpath:spring-config.xml", "classpath:spring-mybatis.xml"})
public class UserTest {

    private static final Logger LOGGER = Logger.getLogger(UserTest.class);

    @Test
    public void test_matches(){
        System.out.println("---------------------------->" + "/login.html".matches("/login|/login/.*|/login.html"));
    }
    @Autowired
    UserService userService;

    @Test
    public void  TestaddUserByEmail(){
        User user=new User();
        user.setUserEmail("1478524444@qq.com");
        user.setUserPassword("577410444");
        System.out.print("<<<<<<<<<<<<<<"+userService.addUserByEmail(user));
    }

    @Test
    public void  TestaddUserByTelphone(){
        User user=new User();
        user.setUserTelphone("15896321489");
        user.setUserPassword("qwerty");
        user.setUserOpenId("123");
        user.setUserLevel(4);
        user.setUserPower(0);
       System.out.print("<<<<<<<<<<<<<<"+userService.addUserByTelphone(user));
    }

    @Test
    public void  TestupdateUserStatePowerOpenIdByUserId(){
        User user=new User();
        user.setUserId(1);
        user.setUserPower(0);
        user.setUserState(0);
        userService.updateUserStatePowerOpenIdByUserId(user);

    }

    @Test
    public void TestupdateUserLevelCredit(){
        User user=new User();
        user.setUserId(1);
        user.setUserLevel(120);
        user.setUserCredit(20);
        userService.updateUserLevelCredit(user);
    }


    @Test
    public void  TestuserInformationInsert(){
        User user=new User();

        user.setUserPassword("wang");
        user.setUserTelphone("15606854847");
        user.setUserEmail("1165479048@qq.com");
        userService.userInformationInsert(user);
    }

    @Test
    public void TestselectUserLevelCredit(){
        User user=new User();
        user.setUserId(1);
       System.out.print("《《《《《《《《《" + JSON.toJSON(userService.selectUserLevelCredit(user)));

    }

    @Test
    public void TestselectUserStatePower(){
        User user=new User();
        user.setUserId(1);
        System.out.print("《《《《《《《《《" + JSON.toJSON(userService.selectUserStatePower(user)));
    }

    @Test
    public  void   TestselectUserIdByTelphon(){
       User user=new User();
        user.setUserTelphone("15606854845");
       int id=userService.selectUserIdByTelphone(user).getUserId();
     System.out.print("<<<<<<<<<<<<<<<<<<<<<" + id);

    }

    @Test
    public  void  TestselectUserIdByEmail(){
        User user=new User();
        user.setUserEmail("1165479047@qq.com");
        System.out.print("<<<<<<<<<<<<<<<<<<<<<" + userService.selectUserIdByuserEmail(user).getUserId());
    }
     @Test
    public  void  TestupdatePasswordByUserId(){

         User user=new User();
         user.setUserId(1);
         user.setUserPassword("wanggaowen");
         userService.updatePasswordByUserId(user);
     }

    @Test
    public  void  TestupdateUserPrivateinfoById(){

        //生成日期对象
        Date current_date =  new Date(2006,0,12);
    //设置日期格式化样式为：yyyy-MM-dd
        SimpleDateFormat SimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
    //格式化当前日期


        User user=new User();
        user.setUserId(1);
        user.setUserEmail("1165479040@qq.com");
        user.setUserTelphone("18532140101");
        user.setUserBirthday(current_date);
        user.setUserDetail("我很开心呀！");
        userService.updateUserPrivateInfoByUserId(user);
        System.out.print("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" + userService.updateUserPrivateInfoByUserId(user));
    }

    @Test
    public  void  TestselectUserPa0rtInfoByUserId(){
        User user=new User();
        user.setUserId(1);
//        LOGGER.info("<<<<<<<<<<<<<<" + JSON.toJSON(userService.selectUserPartInfoByUserId(user))+">>>>>>>>>>>>>>>");

    }

    @Test
    public void get_age(){
        Date a = userService.selectAllUserInfoByUserId(30).getUserBirthday();
        Date b = new Date();
        Integer yeold=b.getYear()-a.getYear();
        System.out.println("------------------->"+a.getYear());
        System.out.println("------------------->"+b.getYear());
        System.out.println("--------------------->当前年龄"+(yeold));
    }
}

